<?php
function db($variable) {
	$db = array();
	$db['website'] = 'http://192.168.0.200:8085/test/';
	$db['dbhost'] = 'localhost'; //MySQL Host
	$db['dbname'] = 'duphp'; //Database Name
	$db['dbuname'] = 'root'; //Database Username
	$db['dbpass'] = '123558'; //Database password
	$db['prefix'] = ''; //Database prefix

	$db['dberror'] = '<strong>There was an error while connecting to the database.</strong> <br /> Check your database settings.'; //Database error message
	return $db[$variable];
}
function connect_to_db() {
	$db = mysql_connect(db('dbhost'), db('dbuname'), db('dbpass'));
	mysql_select_db(db('dbname')) or die(db('dberror'));
    mysql_query("SET NAMES UTF-8");
   if (mysql_num_rows(mysql_query("SHOW TABLES LIKE '".db('prefix')."articles'")) != 1) {
      die(db('db_tables_error'));
   }  
}
function html_input($type, $name, $id, $value, $label, $css, $script1, $script2, $script3, $checked, $rows, $cols, $method, $action, $legend) {
	$lbl = !empty($label) ? '<label for="'.$id.'">'.$label.'</label>' : '';
	$ID = !empty($id) ? ' id="'.$id.'"' : '';
	$style = !empty($css) ? ' class="'.$css.'"' : '';
	$js1 = !empty($script1) ? ' '.$script1 : '';
	$js2 = !empty($script2) ? ' '.$script2 : '';
	$js3 = !empty($script3) ? ' '.$script3 : '';
	$attribs = $ID.$style.$js1.$js2.$js3;
	$val = ' value="'.$value.'"';
	$input = '<input type="'.$type.'" name="'.$name.'"'.$attribs;
	switch($type) {
		case 'form': $output = (!empty($method) && $method != 'end') ? '<form method="'.$method.'" action="'.$action.'"'.$attribs.' >' : '</form>'; break;
		case 'fieldset': $output = (!empty($legend) && $legend != 'end') ? '<fieldset><legend'.$attribs.'>'.$legend.'</legend>' : '</fieldset>'; break;
		case 'text':
		case 'password': $output = '<p>'.$lbl.':<br />'.$input.$val.' /></p>'; break;
		case 'checkbox':
		case 'radio': $check = $checked == 'ok' ? ' checked="checked"' : ''; $output = '<p>'.$input.$check.' /> '.$lbl.'</p>'; break;
		case 'hidden':
		case 'submit':
		case 'reset':
		case 'button': $output = $input.$val.' />'; break;
		case 'textarea': $output = '<p>'.$lbl.':<br /><textarea name="'.$name.'" rows="'.$rows.'" cols="'.$cols.'"'.$attribs.'>'.$value.'</textarea></p>'; break;
	}
	return $output;
}
function l($variable) {

	$l = array();

	#SITE LANGUAGE VARIABLES
	$l['home'] = 'Home';
	$l['home_sef'] = 'home'; //default value is used only if "home_SEF" is not set in the database - allowed characters are [a-z] [A-Z] [0-9] [-] [_]
	$l['archive'] = 'Archive';
	$l['rss_feed'] = 'RSS Feed';
	#表单
	$l['username'] = '用户名';
	$l['psw'] = '密码';
	$l['submit'] = '提交';
	$l['reset'] = '恢复';
	$l['back'] = '返回';
	$l['title'] = '标题';
	$l['content'] = '内容';
	#出错信息
	$l['err_1'] = '用户名和密码不能为空！';
	$l['err_2'] = '参数错误！';	
	return $l[$variable];

}
function Input($url){
	$url = isset($url)?$url:'index.php';
	echo html_input('form', '', '', '','', '', '', '', '', '', '', '', 'post', 'cmd.php','' );
	echo html_input('text', 'title', 'title', '',l('title'),'textinput','','','','','','','','','');
	echo html_input('textarea', 'text', 'text', '',l('content'),'textareainput','','','','','10','30','','','');
	echo html_input('submit', '', '', l('submit'),'','botton','','','','','','','','','');
	echo html_input('button', '', '', l('back'),'','botton','onclick=location="'.$_SERVER['HTTP_REFERER'].'"', '', '', '', '', '', '', '', '');
	echo html_input('hidden', '@cmd_type', '@cmd_type', 'add','', '', '', '', '', '', '', '', '', '', '');
	echo html_input('hidden', '@url', '@url', $url,'', '', '', '', '', '', '', '', '', '', '');
	echo html_input('hidden', 'date', 'date', date('Y-m-d'),'', '', '', '', '', '', '', '', '', '', '');		
	echo html_input('form', 'uname', 'uname', '','', '', '', '', '', '', '', '', 'end', 'cmd.php', '');
}
connect_to_db();

function getHeadHtml($charset='utf-8',$title='',$css_or_js=''){
	return "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Transitional//EN' 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd'>\n<html xmlns='http://www.w3.org/1999/xhtml'>\n<head><meta http-equiv='Content-Type' content='text/html; charset=$charset' />\n $css_or_js \n<title>$title</title>\n</head>"; 	
}
?>
